package com.servlet;

import com.service.AdminService;
import com.service.BookService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/deleteBook")
public class DeleteBookServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String bookidStr = req.getParameter("bookid");
        int bookid = Integer.parseInt(bookidStr);
        boolean b=false;
        try {
            b = new BookService().deleteBookById(bookid);
            if(!b){
                String error="删除不成功，请重新选择";
                req.setAttribute("eerror",error);
            }

            req.getRequestDispatcher("/BookSearch").forward(req,resp);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
